use "replication_data.dta", clear

*** STANDARDIZE MEASURES
foreach i in rate_commish trust_commish efficacy elect_interest intent_support {
	qui sum `i'
	gen std_`i'=(`i'-r(mean))/r(sd)
}
label var std_rate_commish "Board Job Rating"
label var std_trust "Trust Commissioner"
label var std_efficacy "Efficacy"
label var std_elect_interest "Interest in Election"
label var std_intent_support "Intent to Support Commissioner"
alpha std_*, i gen(summary_outcome)
qui sum summary_outcome
replace summary_outcome=(summary_outcome-r(mean))/r(sd)
label var summary_outcome "Favorably Inclined toward Board/Commissioner"


****SUMMARY STATS (TABLE SM.A2)
estpost summarize rate_commish trust efficacy elect_interest intent_support age educ income income_mis Women Men Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other 
eststo pooled, title("Full Sample")
esttab pooled using "sumstats.tex", cells(mean(fmt(a2))) replace title(Summary Statistics \label{sumstats}) addnote(Cell entries are means.) nogaps booktabs wrap varwidth(40) b(%9.3f) se(%9.3f) star(+ 0.10 * 0.05 ** .01) nonotes nodepvars label collabel(none)

****TABLE OF MEANS (TABLE SM.A4)
xtable commis_name, c(mean std_rate_commish  mean std_trust mean std_efficacy mean std_elect_interest mean std_intent_support) file(means_names) replace
xtable commis_name, c(mean familiar_commish mean correct_inference) file(means_names_famil) replace
xtable commis_race, c(mean std_rate_commish  mean std_trust mean std_efficacy mean std_elect_interest mean std_intent_support) file(means_race) replace
xtable commis_race, c(mean familiar_commish mean correct_inference) file(means_race_famil) replace
xtable commis_female, c(mean std_rate_commish  mean std_trust mean std_efficacy mean std_elect_interest mean std_intent_support) file(means_gender) replace
xtable commis_female, c(mean familiar_commish mean correct_inference) file(means_gender_famil) replace


****MAIN REGRESSIONS (TABLE SM.A5; Estimates reported in FIGURE 1)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis Women Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other  i.names_index, r	
estimates store est_`i'
}

coefplot est_std_rate_commish est_std_trust est_std_efficacy est_std_elect_interest est_std_intent_support , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.125).5, labsize(small)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Estimated Treatment Effect (in Standard Deviations)", size(medlarge))  text(.66 -.15 "Board Job Rating" .825 -.23 "Trust Commissioner" .99 -.09 "Efficacy" 1.16 -.36 "Interest in Election" 1.33 -.16 "Intent to Support" 1.66 .26 "Board Job Rating" 1.825 .26 "Trust Commissioner" 1.99 .14 "Efficacy" 2.16 .21 "Interest in Election" 2.33 .19 "Intent to Support",  size(small))
graph save full_sample, replace
graph export "direct_fx.eps", as(eps) replace
graph export "direct_fx.tif", as(tif) replace

esttab est_std_rate_commish est_std_trust est_std_efficacy est_std_elect_interest est_std_intent_support using base_regressions.tex, replace nogaps compress booktabs wrap keep(comm_racematch comm_gendermatch age educ income income_mis Women Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other) varwidth(30) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) nonotes label title("Estimated Effects of Descriptive Rep. Signals"\label{baseregs} \scriptsize) addnote("Cell entries are unstandardized OLS coefficients; robust standard errors in parentheses; $* p < .05; ** p < .01$." "Outcome variables: mean = 0, standard deviation = 1.  All models control for a vector of indicators for the 11 of the 12 Commissioners used as treatments.")


**WITHOUT KNOWN (TABLE SM.A8)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis Women Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other  i.names_index if commis_name!="Brandon Johnson" & commis_name!="John Daley", r	
estimates store est_`i'_NK
}
coefplot est_std_rate_commish_NK est_std_trust_NK est_std_efficacy_NK est_std_elect_interest_NK est_std_intent_support_NK , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.125).5, labsize(small)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Estimated Treatment Effect (in Standard Deviations)", size(medlarge))  text(.66 -.17 "Board Job Rating" .825 -.21 "Trust Commissioner" .99 -.11 "Efficacy" 1.16 -.38 "Interest in Election" 1.33 -.16 "Intent to Support" 1.66 .26 "Board Job Rating" 1.825 .26 "Trust Commissioner" 1.99 .11 "Efficacy" 2.16 .21 "Interest in Election" 2.33 .19 "Intent to Support",  size(small))
graph save full_sample, replace
graph export "direct_fx_not_famous.eps", as(eps) replace
graph export "direct_fx_not_famous.tif", as(tif) replace

esttab est_std_rate_commish_NK est_std_trust_NK est_std_efficacy_NK est_std_elect_interest_NK est_std_intent_support_NK using base_regressions_notknown.tex, replace nogaps compress booktabs wrap keep(comm_racematch comm_gendermatch age educ income income_mis Women Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other) varwidth(30) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) nonotes label title("Estimated Effects of Descriptive Rep. Signals (Exclude Most Recognized Commissioners)"\label{baseregs_notknown} \scriptsize) addnote("Cell entries are unstandardized OLS coefficients; robust standard errors in parentheses; $* p < .05; ** p < .01$." "Outcome variables: mean = 0, standard deviation = 1.  All models control for a vector of indicators for the 11 of the 12 Commissioners used as treatments. Models excludes cases where respondents were treated with Commissioner Brandon Johnson or John Daley.")


**** BY R'S GROUP (FIGURE 2)
label var comm_racematch "Race"
label var comm_gendermatch "Gender"
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis if (race_black|race_hisp|race_white) & gender!=3, r	
estimates store est_`i'
}

coefplot est_std_rate_commish est_std_trust est_std_efficacy est_std_elect_interest est_std_intent_support , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.5).5) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Treatment Effect") title("All") text(.66 -.15 "Rating" .825 -.20 "Trust" .99 -.20 "Efficacy" 1.16 -.39 "Interest" 1.33 -.23 "Support", size(small))
graph save full_sample_nolab, replace

foreach g in Women Men White Black Hispanic{
	qui count if `g'
	local n=r(N)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis if `g'==1 & (race_black|race_hisp|race_white) & gender!=3, r	
estimates store est_`i'
}

coefplot est_std_rate_commish est_std_trust est_std_efficacy est_std_elect_interest est_std_intent_support , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label plotlabels("Board Job Rating" "Trust Commissioner" "Efficacy" "Interest" "Intent to Support" ) legend(off) xtitle("Treatment Effect") title("`g' (N = `n')")
graph save `g', replace
}

graph combine full_sample_nolab.gph Women.gph Men.gph White.gph Black.gph Hispanic.gph,xcommon scheme(s1mono)
graph export "fx_by_group.eps", as(eps) replace
graph export "fx_by_group.tif", as(tif) replace


*SUMMARY OUTCOME MEASURE (TABLE SM.A6)
qui reg summary_outcome comm_racematch comm_gendermatch age educ income income_mis if (race_black|race_hisp|race_white) & gender!=3, r	
estimates store summary_pooled
foreach g in Women Men White Black Hispanic{
reg summary_outcome comm_racematch comm_gendermatch age educ income income_mis if `g'==1 & (race_black|race_hisp|race_white) & gender!=3, r	
estimates store summary_`g'
}
esttab summary_pooled summary_Women summary_Men summary_White summary_Black summary_Hispanic using summary_outcome.tex, replace nogaps compress booktabs wrap  varwidth(30) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) nonotes label title("Mean Index as Outcome Variable"\label{summaryoutcome} \scriptsize)  addnote("Cell entries are unstandardized OLS coefficients; robust standard errors in parentheses; $* p < .05; ** p < .01$." "Outcome variable: mean = 0, standard deviation = 1. Restricted to respondents who identified as Men or Women and White, Black, or Hispanic.")


***INTERACTIONS (TABLE SM.A7)
foreach v in Black Hispanic Women{
	gen `v'Xrace=`v'*comm_racematch 
	gen `v'Xgender=`v'*comm_gendermatch 
label var `v'Xrace "`v' x Race Match"
label var `v'Xgender "`v' x Gender Match"
	}

foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
reg `i' comm_racematch comm_gendermatch  Black Hispanic Women  BlackXrace BlackXgender HispanicXrace HispanicXgender WomenXrace WomenXgender age educ income income_mis if (race_black|race_hisp|race_white) & gender!=3, r
test BlackXrace ==HispanicXrace
test BlackXgender==HispanicXgender
estimates store X_est_`i'
}

esttab X_est_std_rate_commish X_est_std_trust X_est_std_efficacy X_est_std_elect_interest X_est_std_intent_support using interactions.tex, replace nogaps compress booktabs wrap  varwidth(30) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) nonotes label title("Estimated Effects of Descriptive Rep. Signals: Respondent Characteristic Interactions"\label{interactions} \scriptsize) interaction(" x ") nobase addnote("Cell entries are unstandardized OLS coefficients; robust standard errors in parentheses; $* p < .05; ** p < .01$." "Outcome variables: mean = 0, standard deviation = 1. Restricted to respondents who identified as Men or Women and White, Black, or Hispanic.")



**WITHOUT KNOWN (TABLE SM.A9)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch  Black Hispanic Women  BlackXrace BlackXgender HispanicXrace HispanicXgender WomenXrace WomenXgender age educ income income_mis if (race_black|race_hisp|race_white) & gender!=3 & commis_name!="Brandon Johnson" & commis_name!="John Daley", r
	
estimates store est_`i'_XNK
}
esttab est_std_rate_commish_XNK est_std_trust_XNK est_std_efficacy_XNK est_std_elect_interest_XNK est_std_intent_support_XNK using interactions_notknown.tex, replace nogaps compress booktabs wrap varwidth(30) b(%9.3f) se(%9.3f) star(* 0.05 ** .01) nonotes label title("Estimated Effects of Descriptive Rep. Signals: Respondent Characteristic Interactions (Exclude Most Recognized Commissioners)"\label{interactions_notknown} \scriptsize) addnote("Cell entries are unstandardized OLS coefficients; robust standard errors in parentheses; $* p < .05; ** p < .01$." "Outcome variables: mean = 0, standard deviation = 1.  Restricted to respondents who identified as Men or Women and White, Black, or Hispanic. Models excludes cases where respondents were treated with Commissioner Brandon Johnson or John Daley.")


sum TimeAtENDOFP, det
sum TotalTime, det
gen time_on_descriptive=(TimeAtENDOFDe-TimeAtENDOFP)

****BY TIME ON SURVEY (FIGURE SM.A4)
xtile timespent=TimeAtENDOFP, nq(20)

qui sum if timespent>1
local n = r(N)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis i.gender race_white race_hisp race_black race_aind race_hpi race_asian race_other  i.names_index if timespent>1, r	
test comm_racematch 
test comm_gendermatch 
estimates store est_`i'_Q1
}
coefplot est_std_rate_commish_Q1 est_std_trust_Q1 est_std_efficacy_Q1 est_std_elect_interest_Q1 est_std_intent_support_Q1 , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.25).5, labsize(small)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Treatment Effect", size(medlarge)) title("> Ventile 1 (N = `n')")  text(.66 -.15 "Rating" .825 -.20 "Trust" .99 -.15 "Efficacy" 1.16 -.36 "Interest" 1.33 -.18 "Support", size(small))
graph save fx_Q1, replace

forvalues t =2/6{
qui sum if timespent>`t'
local n = r(N)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis i.gender race_white race_hisp race_black race_aind race_hpi race_asian race_other  i.names_index if timespent>`t', r	
disp "`i'"
test comm_racematch 
test comm_gendermatch 
estimates store est_`i'_Q`t'
}
coefplot est_std_rate_commish_Q`t' est_std_trust_Q`t' est_std_efficacy_Q`t' est_std_elect_interest_Q`t' est_std_intent_support_Q`t' , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.25).5, labsize(small)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Treatment Effect", size(medlarge)) title("> Ventile `t' (N = `n')")
graph save fx_Q`t', replace
}

graph combine fx_Q1.gph fx_Q2.gph fx_Q3.gph fx_Q4.gph fx_Q5.gph fx_Q6.gph,xcommon scheme(s1mono)
graph export "fx_by_time.eps", as(eps) replace
graph export "fx_by_time.tif", as(tif) replace


***MAIN, ROBUST TO NO NAME CONTROLS (FIGURE SM.A3)
foreach i in std_rate_commish std_trust std_efficacy std_elect_interest std_intent_support{
qui reg `i' comm_racematch comm_gendermatch age educ income income_mis Women Other_Gend race_white race_hisp race_black race_aind race_hpi race_asian race_other, r	
estimates store nn_est_`i'
}

coefplot est_std_rate_commish est_std_trust est_std_efficacy est_std_elect_interest est_std_intent_support , keep(comm_racematch comm_gendermatch) xline(0, lcolor(black) lwidth(thin)) level(95) graphregion(fcolor(white) lcolor(none) ilcolor(none) color(white) lwidth(large)) xlabel(-.5(.125).5, labsize(small)) xscale(lw(none)) ylabel(,labsize(medium) angle(vertical)) mcolor(black) msize(small) label legend(off) xtitle("Estimated Treatment Effect (in Standard Deviations)", size(medlarge))  text(.66 .32 "Board Job Rating" .825 .14 "Trust Commissioner" .99 .30 "Efficacy" 1.16 .32 "Interest in Election" 1.33 .34 "Intent to Support" 1.66 -.23 "Board Job Rating" 1.825 -.22 "Trust Commissioner" 1.99 -.21 "Efficacy" 2.16 -.26 "Interest in Election" 2.33 -.35 "Intent to Support",  size(small))
graph save full_sample_noname_ctrls, replace
graph export "direct_fx_noname_ctrls.eps", as(eps) replace



